﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

#include "RpcSharedObject.h"
#include "UniIdentity.h"
#include "IGraphicsElementShape.h"
#include "IGraphicsStyleData.h"
#include "IGraphicsMaterialData.h"
#include "IFillPatternData.h"
#include "ILineTypeData.h"
#include "OwnerPtr.h"
#include "Matrix4d.h"
#include "Vector3d.h"
#include "IPlane.h"
#include "IModelView.h"

namespace gcmp
{
    // 在位编辑共享视图信息
    class GM_INPLACE_EDIT_EXPORT InplaceEditSharedModelViewInfo : public RpcSharedObject
    {
        CANNOT_COPY_OR_ASSIGN(InplaceEditSharedModelViewInfo)
        DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedModelViewInfo, gcmp::RpcSharedObject, A11647FE - BAC2 - 47AD - AA29 - F16C99ECA3E6, gminplaceedit)
            DATA(std::wstring, ViewType)
            DATA(std::wstring, ViewName)
            DATA(Vector3d, Origin)
            DATA(Vector3d, ViewDirection)
            DATA(Vector3d, RightDirection)
            DATA(Vector3d, UpDirection)
            DATA(OwnerPtr<IPlane>, WorkPlane)
            DATA(BuiltInViewType, BuiltInViewType)
        DBOBJECT_DATA_END

    public:
        InplaceEditSharedModelViewInfo(const std::wstring& viewType, const std::wstring& viewName, BuiltInViewType builtInViewType);
        
    public:
        const std::wstring& GetViewType() const { return this->GetViewType__(); }
        bool SetViewType(const std::wstring& viewType) { this->SetViewType__(viewType); return true; }
        const std::wstring& GetViewName() const { return this->GetViewName__(); }
        bool SetViewName(const std::wstring& viewName) { this->SetViewName__(viewName); return true; }
        const Vector3d& GetOrigin() const { return this->GetOrigin__(); }
        bool SetOrigin(const Vector3d& pt) { this->SetOrigin__(pt); return true; }
        const Vector3d& GetViewDirection() const { return this->GetViewDirection__(); }
        bool SetViewDirection(const Vector3d& dir) { this->SetViewDirection__(dir); return true; }
        const Vector3d& GetRightDirection() const { return this->GetRightDirection__(); }
        bool SetRightDirection(const Vector3d& dir) { this->SetRightDirection__(dir); return true; }
        const Vector3d& GetUpDirection() const { return this->GetUpDirection__(); }
        bool SetUpDirection(const Vector3d& dir) { this->SetUpDirection__(dir); return true; }
        const IPlane* GetWorkPlane() const { return this->GetWorkPlane__().get(); }
        bool SetWorkPlane(OwnerPtr<IPlane> opWorkPlane) { this->SetWorkPlane__(TransferOwnership(opWorkPlane)); return true; }
        BuiltInViewType GetBuiltInViewType() const { return this->GetBuiltInViewType__(); }
        bool SetBuiltInViewType(BuiltInViewType viewType) { this->SetBuiltInViewType__(viewType); return true; }
    };

    // 在位编辑共享样式信息
    class GM_INPLACE_EDIT_EXPORT InplaceEditSharedGraphicsStyleInfo : public RpcSharedObject
    {
        DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedGraphicsStyleInfo, gcmp::RpcSharedObject, A6108323 - 748F - 47E9 - B5FD - 31080317DEE0, gminplaceedit)
            DATA(ElementId, StyleId)
            DATA(Color, Color)
            DATA(double, Transparency)
            DATA(Color, ProjectionLineColor)
            DATA(SmartColorMode, ProjectionLineColorSmart)

            DATA(Bool, IsProjectionLineColorAlphaEnabled)
            DATA(double, ProjectionLineWidth)
            DATA(Bool, IsProjectionLineWidthModePixel)
            DATA(std::wstring, ProjectionLineTypeName)
            DATA(double, ProjectionLineTypeScale)
            DATA(Color, SectionLineColor)
            DATA(SmartColorMode, SectionLineColorSmart)

            DATA(double, SectionLineWidth)
            DATA(Bool, IsSectionLineWidthModePixel)
            DATA(std::wstring, SectionLineTypeName)
            DATA(double, SectionLineTypeScale)
            DATA(Color, HiddenLineColor)
            DATA(SmartColorMode, HiddenLineColorSmart)

            DATA(double, HiddenLineWidth)
            DATA(Bool, IsHiddenLineWidthModePixel)
            DATA(std::wstring, HiddenLineTypeName)
            DATA(double, HiddenLineTypeScale)
            DATA(Color, ProjectionFaceHatchColor)
            DATA(double, ProjectionFaceHatchLineWidth)
            DATA(std::wstring, ProjectionFaceHatchPattern)
            DATA(double, ProjectionFaceHatchScale)
            DATA(double, ProjectionFaceHatchRotation)
            DATA(Color, SectionFaceHatchColor)
            DATA(std::wstring, SectionFaceHatchPattern)
            DATA(double, SectionFaceHatchScale)
            DATA(double, SectionFaceHatchRotation)
        DBOBJECT_DATA_END

    public:
        InplaceEditSharedGraphicsStyleInfo(const IGraphicsStyleData* pStyleData);
        OwnerPtr<IGraphicsStyleData> GetAsGraphicsStyleData() const;
        ElementId GetStyleId() const { return GetStyleId__(); }
        void SetStyleId(const ElementId& styleId) { SetStyleId__(styleId); }
    };
    ///共享填充类型
    class GM_INPLACE_EDIT_EXPORT InplaceEditSharedFillPatternInfo : public RpcSharedObject
    {
        DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedFillPatternInfo, gcmp::RpcSharedObject,  5378117F - 0E22 - 46BF - 9951 - AECA62BC1A98 , gminplaceedit)
            DATA(ElementId, GenericId)
            DATA(std::wstring, Name)
            DATA(std::wstring, Description)
            DATA(std::wstring, PatternString)
            DATA(double, Scale)
            DATA(double, RotateAngle)
            DATA(Bool, IsSolid)
            DATA(FillPatternTarget, Target)
            DBOBJECT_DATA_END

    public:
        InplaceEditSharedFillPatternInfo(const IFillPatternData* pFillPatternData);
        OwnerPtr<IFillPatternData> GetAsFillPatternData() const;
        ElementId GetGenericId() const { return GetGenericId__(); }
        void SetGenericId(const ElementId& genericId) { SetGenericId__(genericId); }
    };
    ///共享线型
    class GM_INPLACE_EDIT_EXPORT InplaceEditSharedLineTypeNewInfo : public RpcSharedObject
    {
        DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedLineTypeNewInfo, gcmp::RpcSharedObject,  B1A55EC0 - 85E8 - 4B8D - 8106 - 361DE90E67D9 , gminplaceedit)
            DATA(ElementId, GenericId)
            DATA(std::wstring, Name)
            DATA(std::wstring, Description)
            DATA(std::wstring, PatternStr)
            DBOBJECT_DATA_END

    public:
        InplaceEditSharedLineTypeNewInfo(const ILineTypeData* pLineTypeData);
        OwnerPtr<ILineTypeData> GetAsLineTypeData() const;
        ElementId GetGenericId() const { return GetGenericId__(); }
        void SetGenericId(const ElementId& genericId) { SetGenericId__(genericId); }
    };

    // 在位编辑共享材质信息
    class InplaceEditSharedGraphicsMaterialInfo : public RpcSharedObject
    {
        DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedGraphicsMaterialInfo, gcmp::RpcSharedObject, 2B9DC0D5 - EA5B - 4B67 - AF31 - CE360A4FA6CA, gminplaceedit)
            DATA(ElementId, MaterialId)
            DATA(Color, Ambient)
            DATA(Color, Diffuse)
            DATA(Color, Specular)
            DATA(double, Transparency)
            DATA(double, Shininess)
            DATA(Bool, IsDiffuseTextureEnabled)
            DATA(std::wstring, DiffuseTextureFilePath)
            DATA(Vector2d, DiffuseTexureOffset)
            DATA(double, DiffuseTexureRotation)
            DATA(Vector2d, DiffuseTexureScale)
        DBOBJECT_DATA_END

    public:
        InplaceEditSharedGraphicsMaterialInfo(const IGraphicsMaterialData* pMaterialData);
        OwnerPtr<IGraphicsMaterialData> GetAsGraphicsMaterialData() const;
        ElementId GetMaterialId() const { return GetMaterialId__(); }
        void SetMaterialId(const ElementId& materialId) { SetMaterialId__(materialId); }
    };

    // 在位编辑共享类别信息
    class InplaceEditSharedCategoryInfo : public RpcSharedObject
    {
        DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedCategoryInfo, gcmp::RpcSharedObject, EE71FECC - C8D1 - 47B5 - 90BA - 9920F6FE3F90, gminplaceedit)
            DATA(UniIdentity, CategoryUid)
            DATA(ElementId, StyleId)
            DATA(ElementId, MaterialId)
        DBOBJECT_DATA_END

    public:
        InplaceEditSharedCategoryInfo(const UniIdentity& categoryUid, const ElementId& styleId, const ElementId& materialId);

    public:
        const UniIdentity& GetCategoryUid() const { return this->GetCategoryUid__(); }
        bool SetCategoryUid(const UniIdentity& uid) { this->SetCategoryUid__(uid); return true; }
        const ElementId& GetStyleId() const { return this->GetStyleId__(); }
        bool SetStyleId(const ElementId& id) { this->SetStyleId__(id); return true; }
        const ElementId& GetMaterialId() const { return this->GetMaterialId__(); }
        bool SetMaterialId(const ElementId& id) { this->SetMaterialId__(id); return true; }
    };

    // 在位编辑共享数据
    class GM_INPLACE_EDIT_EXPORT InplaceEditSharedContent : public RpcSharedObject
    {
        CANNOT_COPY_OR_ASSIGN(InplaceEditSharedContent)
        DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedContent, gcmp::RpcSharedObject, EC55BE3E - 0DA5 - 4761 - 9903 - D0A91DEE32D8, gminplaceedit)
            ARR_DATA(OwnerPtr<InplaceEditSharedModelViewInfo>, ViewInfos)
            ARR_DATA(InplaceEditSharedCategoryInfo, CategoryInfos)
            DATA(Vector3d, InsertionPoint)
            DATA(std::wstring, DefaultCommand)
            DATA(ElementId, EditingElementId)
            DATA(UniIdentity, CategoryId)
            DATA(std::wstring, EditFamilyFilePath)
            DATA(std::wstring, FamilyName)
            DATA(std::wstring, CurrentViewName)
            DATA(UInt16, ProjectAppPort)
        DBOBJECT_DATA_END

    public:
        const std::vector<OwnerPtr<InplaceEditSharedModelViewInfo>>& GetViewInfos() const { return this->GetViewInfos__(); }
        bool SetViewInfos(std::vector<OwnerPtr<InplaceEditSharedModelViewInfo>>&& infos) { this->GetViewInfosFW__() = std::move(infos); return true; }


        const std::vector<InplaceEditSharedCategoryInfo>& GetCategoryInfos() const { return this->GetCategoryInfos__(); }
        bool SetCategoryInfos(const std::vector<InplaceEditSharedCategoryInfo>& infos) { this->SetCategoryInfos__(infos); return true; }
        const Vector3d& GetInsertionPoint() const { return this->GetInsertionPoint__(); }
        bool SetInsertionPoint(const Vector3d& pt) { this->SetInsertionPoint__(pt); return true; }
        const std::wstring& GetDefaultCommand() const { return this->GetDefaultCommand__(); }
        bool SetDefaultCommand(const std::wstring& cmd) { this->SetDefaultCommand__(cmd); return true; }
        const ElementId& GetEditingElementId() const { return this->GetEditingElementId__(); }
        bool SetEditingElementId(const ElementId& id) { this->SetEditingElementId__(id); return true; }
        UniIdentity GetCategoryId() const { return this->GetCategoryId__(); }
        bool SetCategoryId(const UniIdentity& id) { this->SetCategoryId__(id); return true; }
        const std::wstring& GetEditFamilyFilePath() const { return this->GetEditFamilyFilePath__(); }
        bool SetEditFamilyFilePath(const std::wstring& familyFilePath) { this->SetEditFamilyFilePath__(familyFilePath); return true; }
        const std::wstring& GetFamilyName() const { return this->GetFamilyName__(); }
        bool SetFamilyName(const std::wstring& name) { this->SetFamilyName__(name); return true; }
        const std::wstring& GetCurrentViewName() const { return this->GetCurrentViewName__(); }
        bool SetCurrentViewName(const std::wstring& name) { this->SetCurrentViewName__(name); return true; }

        uint16_t GetProjectAppPort() const { return GetProjectAppPort__(); }
        void SetProjectAppPort(uint16_t port) { SetProjectAppPort__(port); }
    };


    // 在位编辑共享视图图形信息
    class GM_INPLACE_EDIT_EXPORT InplaceEditSharedElementInfo : public RpcSharedObject
    {
        DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedElementInfo, gcmp::RpcSharedObject, F2981C33 - D2B0 - 425B - 8A57 - 987912BEB7F0, gminplaceedit)
            DATA(UniIdentity, CategoryUid)
            DATA(OwnerPtr<IGraphicsElementShape>, GRep)
        DBOBJECT_DATA_END

    public:
        const UniIdentity& GetCategoryUid() const { return this->GetCategoryUid__(); }
        bool SetCategoryUid(const UniIdentity& uid) { this->SetCategoryUid__(uid); return true; }
        const IGraphicsElementShape* GetGRep() const { return this->GetGRep__().get(); }
        bool SetGRep(OwnerPtr<IGraphicsElementShape> op) { this->SetGRep__(op); return true; }
        OwnerPtr<IGraphicsElementShape> FetchGRep() { return TransferOwnership(this->GetGRepFW__()); }
    };


    // 相机参数
    class GM_INPLACE_EDIT_EXPORT InplaceEditSharedCameraInfo : public RpcSharedObject
    {
        DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedCameraInfo, gcmp::RpcSharedObject, 90A29B19 - 6FA0 - 4128 - 9437 - B5CD45E3BCAC, gminplaceedit)
            DATA(Int32, Type)
            DATA(Vector3d, Position)
            DATA(Vector3d, Direction)
            DATA(Vector3d, UpDirection)
            DATA(double, AspectRatio)
            DATA(double, NearDist)
            DATA(double, FarDist)
            DATA(double, FieldOfView)
            DATA(double, OrthoWindowHeight)
        DBOBJECT_DATA_END

    public:
        Int32 GetType() const { return this->GetType__(); }
        bool SetType(int type) { this->SetType__(type); return true; }
        const Vector3d& GetPosition() const { return this->GetPosition__(); }
        bool SetPosition(const Vector3d& pt) { this->SetPosition__(pt); return true; }
        const Vector3d& GetDirection() const { return this->GetDirection__(); }
        bool SetDirection(const Vector3d& dir) { this->SetDirection__(dir); return true; }
        const Vector3d& GetUpDirection() const { return this->GetUpDirection__(); }
        bool SetUpDirection(const Vector3d& dir) { this->SetUpDirection__(dir); return true; }
        double GetAspectRatio() const { return this->GetAspectRatio__(); }
        bool SetAspectRatio(double val) { this->SetAspectRatio__(val); return true; }
        double GetNearDist() const { return this->GetNearDist__(); }
        bool SetNearDist(double val) { this->SetNearDist__(val); return true; }
        double GetFarDist() const { return this->GetFarDist__(); }
        bool SetFarDist(double val) { this->SetFarDist__(val); return true; }
        double GetFieldOfView() const { return this->GetFieldOfView__(); }
        bool SetFieldOfView(double val) { this->SetFieldOfView__(val); return true; }
        double GetOrthoWindowHeight() const { return this->GetOrthoWindowHeight__(); }
        bool SetOrthoWindowHeight(double val) { this->SetOrthoWindowHeight__(val); return true; }
    };

    // 在位编辑共享视图数据
    class GM_INPLACE_EDIT_EXPORT InplaceEditSharedViewContent : public RpcSharedObject
    {
        CANNOT_COPY_OR_ASSIGN(InplaceEditSharedViewContent)
        DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedViewContent, gcmp::RpcSharedObject, 07045AAE - B66C - 44C9 - A179 - 2CB100E1F84A, gminplaceedit)
            DATA(std::wstring, ViewName)
            ARR_DATA(OwnerPtr<InplaceEditSharedElementInfo>, SharedElementInfos)
            DATA(OwnerPtr<InplaceEditSharedCameraInfo>, CameraInfo)
            ARR_DATA(OwnerPtr<InplaceEditSharedGraphicsStyleInfo>, StyleInfo)
            ARR_DATA(OwnerPtr<InplaceEditSharedGraphicsMaterialInfo>, MaterialInfo)
            ARR_DATA(OwnerPtr<InplaceEditSharedFillPatternInfo>, FillPatternInfo)
            ARR_DATA(OwnerPtr<InplaceEditSharedLineTypeNewInfo>, LineTypeNewInfo)
        DBOBJECT_DATA_END

    public:
        const std::vector<OwnerPtr<InplaceEditSharedElementInfo>>& GetSharedElementInfos() const { return this->GetSharedElementInfos__(); }
        std::vector<OwnerPtr<InplaceEditSharedElementInfo>>& GetSharedElementInfosFW() { return this->GetSharedElementInfosFW__(); }
        const InplaceEditSharedCameraInfo* GetCameraInfo() const { return this->GetCameraInfo__().get(); }
        bool SetCameraInfo(OwnerPtr<InplaceEditSharedCameraInfo> info) { this->SetCameraInfo__(info); return true; }
        std::wstring GetViewName() const { return this->GetViewName__(); }
        bool SetViewName(const std::wstring& name) { this->SetViewName__(name); return true; }

        bool IsStyleExist(const ElementId& styleId) const;
        bool IsMaterialExist(const ElementId& materialId) const;
        bool IsFillPatternExist(const ElementId& genericId) const;
        bool IsLineTypeNewExist(const ElementId& genericId) const;
        bool AddStyleInfo(const ElementId& styleId, const IGraphicsStyleData* pStyleData);
        bool AddMaterialInfo(const ElementId& materialId, const IGraphicsMaterialData* pMaterialData);
        bool AddFillPatternInfo(const ElementId& genericId, const IFillPatternData* pFillPatternData);
        bool AddLineTypeNewInfo(const ElementId& genericId, const ILineTypeData* pLineTypeData);
        const std::vector<OwnerPtr<InplaceEditSharedGraphicsStyleInfo>>& GetStyleInfos() const;
        const std::vector<OwnerPtr<InplaceEditSharedGraphicsMaterialInfo>>& GetMaterialInfos() const;
        const std::vector<OwnerPtr<InplaceEditSharedFillPatternInfo>>& GetFillPatternInfos() const;
        const std::vector<OwnerPtr<InplaceEditSharedLineTypeNewInfo>>& GetLineTypeNewInfos() const;
    };

    // 在位编辑共享脚本数据
    class GM_INPLACE_EDIT_EXPORT InplaceEditSharedJournalContent : public RpcSharedObject
    {
        CANNOT_COPY_OR_ASSIGN(InplaceEditSharedJournalContent)
            DBOBJECT_DATA_BEGIN(gcmp, InplaceEditSharedJournalContent, gcmp::RpcSharedObject, 20dba2ff - 0668 - 4cb6 - a533 - c73d42026278, gminplaceedit)
            MAP_DATA(std::wstring, std::wstring, JournalMessage)// element 可见性过滤器
            DBOBJECT_DATA_END

    public:
        const std::map<std::wstring, std::wstring>& GetJournalMessage() const { return this->GetJournalMessage__(); }
        bool SetJournalMessage(const std::map<std::wstring, std::wstring>& message) { this->SetJournalMessage__(message); return true; }
    };

}// namespace gcmp
